﻿function Button(node) {
    this.node = node;
    this.item = null;
}

Button.getButtonNodeQuery = function(parentItemId, qualifiedName) {
    return "div[name = '" + parentItemId + '/' + qualifiedName + "']";
}

Button.get = function(item) {
    var node = $(Button.getButtonNodeQuery(item.getParentItem().getId(), item.getQualifiedName()), item.getParentItem().getButtonContainer())[0];
    var button = new Button(node);
    button.item = item;
    return button
}

Button.prototype = {
    show: function() {
        if (this.node) {
            this.node.style.display = "";
        }
    },

    hide: function() {
        if (this.node) {
            this.node.style.display = "none";
        }
    },

    refresh: function() {
        if (this.item.getMaxOccurs() <= this.item.getSiblings().length) {
            this.hide();
        } else {
            this.show();
        }
        $(this.item.node).click();
    }
}